//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "InverseCumulativeStudent.h"
using namespace Cephei::QL::Math::Distributions;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Distributions::CInverseCumulativeStudent::CInverseCumulativeStudent (Int32 n, Microsoft::FSharp::Core::FSharpOption<Double>^ accuracy, Microsoft::FSharp::Core::FSharpOption<UInt64>^ maxIterations) 
{
	_pSpinlock = new boost::detail::spinlock ();
    try
    {
#ifdef HANDLE
        _phInverseCumulativeStudent = NULL;
#endif
        QuantLib::Integer _n = (QuantLib::Integer)ValueHelper::Convert (n);
        QuantLib::Real _accuracy = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (accuracy) ? (QuantLib::Real)ValueHelper::Convert (accuracy->Value) : 1e-6); //4
        QuantLib::Size _maxIterations = 
            (Microsoft::FSharp::Core::FSharpOption<UInt64>::IsSome::get (maxIterations) ? (QuantLib::Size)ValueHelper::Convert (maxIterations->Value) : 50); //4
        _ppInverseCumulativeStudent = new boost::shared_ptr<QuantLib::InverseCumulativeStudent> (new QuantLib::InverseCumulativeStudent ( _n,  _accuracy,  _maxIterations ));
        
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::Distributions::CInverseCumulativeStudent::CInverseCumulativeStudent (boost::shared_ptr<QuantLib::InverseCumulativeStudent>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phInverseCumulativeStudent = NULL;
#endif
	_ppInverseCumulativeStudent = &childNative;
    
}
Cephei::QL::Math::Distributions::CInverseCumulativeStudent::CInverseCumulativeStudent (QuantLib::InverseCumulativeStudent& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phInverseCumulativeStudent = NULL;
#endif
	_ppInverseCumulativeStudent = new boost::shared_ptr<QuantLib::InverseCumulativeStudent> (&childNative);
    
    _InverseCumulativeStudentOwner = owner;
    
}

Cephei::QL::Math::Distributions::CInverseCumulativeStudent::CInverseCumulativeStudent (CInverseCumulativeStudent^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phInverseCumulativeStudent = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppInverseCumulativeStudent = new boost::shared_ptr<QuantLib::InverseCumulativeStudent> (copy->GetShared());
        
    }
}
Cephei::QL::Math::Distributions::CInverseCumulativeStudent::CInverseCumulativeStudent (System::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phInverseCumulativeStudent = NULL;
#endif
	if (!t->IsSubclassOf(CInverseCumulativeStudent::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Distributions::CInverseCumulativeStudent::CInverseCumulativeStudent (QuantLib::Handle<QuantLib::InverseCumulativeStudent>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phInverseCumulativeStudent = &childNative;
	_ppInverseCumulativeStudent = &static_cast<boost::shared_ptr<QuantLib::InverseCumulativeStudent>>(childNative.currentLink());
    
    _InverseCumulativeStudentOwner = owner;
}
Cephei::QL::Math::Distributions::CInverseCumulativeStudent::CInverseCumulativeStudent (QuantLib::Handle<QuantLib::InverseCumulativeStudent> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phInverseCumulativeStudent = &childNative;
	_ppInverseCumulativeStudent = &static_cast<boost::shared_ptr<QuantLib::InverseCumulativeStudent>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Distributions::CInverseCumulativeStudent::CInverseCumulativeStudent (QuantLib::InverseCumulativeStudent childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phInverseCumulativeStudent = NULL;
#endif
	_ppInverseCumulativeStudent = new boost::shared_ptr<QuantLib::InverseCumulativeStudent> (new QuantLib::InverseCumulativeStudent (childNative));
    
}
#endif

Cephei::QL::Math::Distributions::CInverseCumulativeStudent::~CInverseCumulativeStudent ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppInverseCumulativeStudent != NULL)
    {
	    delete _ppInverseCumulativeStudent;
        _ppInverseCumulativeStudent = NULL;
    }
}
Cephei::QL::Math::Distributions::CInverseCumulativeStudent::!CInverseCumulativeStudent ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppInverseCumulativeStudent != NULL)
    {
	    delete _ppInverseCumulativeStudent;
    }
}
QuantLib::InverseCumulativeStudent& Cephei::QL::Math::Distributions::CInverseCumulativeStudent::GetReference ()
{
    if (_ppInverseCumulativeStudent == NULL) throw gcnew NativeNullException ();
	return **_ppInverseCumulativeStudent;
}
boost::shared_ptr<QuantLib::InverseCumulativeStudent>& Cephei::QL::Math::Distributions::CInverseCumulativeStudent::GetShared ()
{
    if (_ppInverseCumulativeStudent == NULL) throw gcnew NativeNullException ();
	return *_ppInverseCumulativeStudent;
}
QuantLib::InverseCumulativeStudent* Cephei::QL::Math::Distributions::CInverseCumulativeStudent::GetPointer ()
{
    if (_ppInverseCumulativeStudent == NULL) throw gcnew NativeNullException ();
	return &**_ppInverseCumulativeStudent;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::InverseCumulativeStudent>& Cephei::QL::Math::Distributions::CInverseCumulativeStudent::GetHandle ()
{
	if (_phInverseCumulativeStudent == NULL)
	{
		_phInverseCumulativeStudent = new Handle<QuantLib::InverseCumulativeStudent> (*_ppInverseCumulativeStudent);
	}
	return *_phInverseCumulativeStudent;
}
#endif
bool Cephei::QL::Math::Distributions::CInverseCumulativeStudent::HasNative () 
{
	return (_ppInverseCumulativeStudent != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Math::Distributions::IInverseCumulativeStudent^ Cephei::QL::Math::Distributions::CInverseCumulativeStudent_Factory::Create (Int32 n, Microsoft::FSharp::Core::FSharpOption<Double>^ accuracy, Microsoft::FSharp::Core::FSharpOption<UInt64>^ maxIterations)
{
    return gcnew CInverseCumulativeStudent ( n,  accuracy,  maxIterations);
}
